home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1538 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.8 KB  |  66 lines

  1. Path: gate.net!not-for-mail
  2. From: feathers@gate.net (Michael Feathers)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  4. Subject: Re: Hungarian notation
  5. Followup-To: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  6. Date: 11 Jan 1996 07:44:45 -0500
  7. Organization: CyberGate, Inc.
  8. Message-ID: <4d30nt$1d4e@hopi.gate.net>
  9. References: <30C40F77.53B5@swsbbs.com> <marnoldDJEvtJ.1Lx@netcom.com> <4aleun$jlk@ns.RezoNet.NET> <marnoldDJMDBG.CFz@netcom.com> <4asnkr$7b0@solutions.solon.com> <4ath75$e7i@barnacle.iol.ie> <4b4kij$svt@news.microsoft.com> <dewar.819489496@schonberg> <4bd
  10.  <4cf8hf$8fe@hopi.gate.net> <4cgq30$c0v@weck.brokersys.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl>
  11. NNTP-Posting-Host: hopi.gate.net
  12. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  13.  
  14. Jos A. Horsmeier (jos@and.nl) wrote:
  15. : Just adding domain name prefixes to the names of objects doesn't help
  16. : anyone; notion of domains should be present in the language itself if
  17. : one really wants domains, instead of just comparable types as implemented
  18. : in the C language. Any (decent) C compiler feels perfectly fine if one
  19. : feeds it something like:
  20. :     #include <stdio.h>
  21. :     #include <string.h>
  22. :     typedef char* empnm_t;
  23. :     typedef char* beernm_t;
  24. :     int main() {
  25. :     empnm_t empnmBoss     = "Clinton";
  26. :     beern_t beernMyFavBeer= "Grolsch";
  27. :     if (!strcmp(empnmBoss, beernMyFavBeer))
  28. :         printf("huh?\n");
  29. :     return 0;
  30. :     }
  31. : The type definitions don't help, the prefixes don't add any clarity
  32. : and still the program would run fine. If domains would have been implemented
  33. : in C, both typedefs could have been changed into something like:
  34. :     domain char* empnm_d;
  35. :     domain char* beernm_d;
  36. : and the compiler would have complained while parsing the arguments of
  37. : the strcmp() function, i.e. two different domains were compared ...
  38. : But if domains were implemented in C, we still don't need those explicit
  39. : prefixes, because the compiler would have warned us about those domain
  40. : violations, and, like you wrote above: if the semantics change, i.e. the
  41. : domains change, one still has to change those prefixes accordingly if
  42. : one used them ...
  43.  
  44. If you want those domains, you can have them in C++.  You easily make 
  45. simple classes that are functionally equivalent but with different
  46. types to give you the domain safety that you want.  You could even
  47. use inheritance to this end.  Make a simple EmployeeName class which 
  48. inherits string and a BeerName class which does also.  Assignment won't
  49. be permitted.  As to the use of strcmp, well.. the operator== of
  50. your classes won't permit that either.
  51.  
  52. I think that your idea of domains is really a call for a more versatile
  53. type system, and that is C++.
  54.  
  55.